﻿<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24MGI/Map24MGI.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------


// coordinates of the location to add
$longitude 				= "417.54556";
$latitude 				= "3056.8179";

// symbol used 	to display the location
$symbolId				= "0";

//description
$discription 			= "Köln";

// zoomlevel
$mapViewClippingWidth 	= 1000;
$ViewPercentage 		= 20;

// MGI Settings
$ImageWidth 			= 600;
$ImageHeight			= 400;
$MimeType				= 'image/gif';


// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// here are all commands defined and are put together in one ArrayOfCommands

// this object will add a new location
$cmdIdx=0;
$commands[$cmdIdx] = new XMLCommandWrapper();
$commands[$cmdIdx]->DeclareMap24Location = new DeclareMap24Location();
$commands[$cmdIdx]->DeclareMap24Location->MapObjectID = "location";
$commands[$cmdIdx]->DeclareMap24Location->Coordinate = new Coordinate();
$commands[$cmdIdx]->DeclareMap24Location->Coordinate->Longitude = $longitude;
$commands[$cmdIdx]->DeclareMap24Location->Coordinate->Latitude = $latitude;
$commands[$cmdIdx]->DeclareMap24Location->SymbolID = $symbolId;

// this object will enable the new location on the map
$cmdIdx++;
$commands[$cmdIdx] = new XMLCommandWrapper();
$commands[$cmdIdx]->ControlMapObject = new ControlMapObject();
$commands[$cmdIdx]->ControlMapObject->Control = "SHOW";
$commands[$cmdIdx]->ControlMapObject->MapObjectIDs = array("location");

// this object will center the map above the new location
$cmdIdx++;
$commands[$cmdIdx] = new XMLCommandWrapper();
$commands[$cmdIdx]->SetMapView = new SetMapView();
$commands[$cmdIdx]->SetMapView->MapObjectIDs = array("location");
$commands[$cmdIdx]->SetMapView->ClippingWidth = new SetMapViewClippingWidth();
$commands[$cmdIdx]->SetMapView->ClippingWidth->MinimumWidth = $mapViewClippingWidth;
$commands[$cmdIdx]->SetMapView->ViewPercentage = $ViewPercentage;

// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request = new RenderBitmapImageRequest();
$request->MRC = new Map24MRC();
$request->MRC->Commands = $commands;
$request->BitmapDescriptor= new BitmapDescriptor();
$request->BitmapDescriptor->ImageWidth = $ImageWidth;
$request->BitmapDescriptor->ImageHeight = $ImageHeight;
$request->BitmapDescriptor->MimeType = $MimeType;


// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
$mrc = new Map24MGI($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);
$response = $mrc->renderBitmapImage($header,$request);


// ------------------------------------------------------------------
// SAVE IMG DATA IN THE SESSION
// ------------------------------------------------------------------


// Save the BitmapData in the Session, to show it in another file
$_SESSION['IMG']=base64_encode($response->BitmapData);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


$resultString = "";
$counter = 0;

if(isset($response->BitmapData) )
{
	$resultString = "<img src='./img.php?" . SID . "' border='0'>";
}

else
{
	$resultString = "Sorry, no answer from the webservices";
}

?>